---
output:
 pdf_document: default
 html_document: default
---
# README

## Replication files for "Negative Political Identities and Costly Political Action", by Katharina Lawall, Stuart J. Turnbull-Dugarte, Florian Foos and Joshua Townsley

This folder includes all the data and code files to replicate the results from both the main Article and the Online Appendix. Most of them have been run using R 4.2.1 on Windows 10. We include the output from `sessionInfo()` at the end of this readme file. **NOTE:** The joint balance test analyses need more time to run, around 4 hours. The rest of the code just takes a few minutes to build.

---

### Data

- [`fieldexpdata.csv`](.): data from the field experiment
- [`surveydata.csv`](.): data from the additional survey
- [`BES2019_W19.dtav`](.): data from wave 19 of the BES online panel 
- [`BES2019_W23.dta`](.): data from wave 23 of the BES online panel 

---

### Other files 

- [`codebook`](.): codebook with variable description for all datasets


---

### Code

The `setwd` command is commented out in every file. Remember to change it to the current directory. You may have to install packages if you receive an error message when trying to load a package. 


- [`replication-main-figs`](.): creates all figures presented in the main paper
- [`replication-appendix`](.): creates most of the Appendix tables and figures, apart from Appendix A.2.1, A.12 and A.13
- [`replication-appendix-jointbalance`](.): creates the Appendix A.2.1 joint balance figure
- [`replication-appendix-survey`](.): creates the Appendix A.13 additional survey tables and figures
- [`replication-appendix-BES`](.): creates the Appendix A.12 figures from the British Election Study data

---

### OS and software

Most of the analyses can be run on a normal computer. We have used R 4.2.1 on Windows 10 64-bit with 64GB of RAM, as well as run this code on a Macbook operating on MacOS Monterrey (12.3) with 32GB of RAM.

One script (the `replication-appendix-jointbalance`), however, requires more memory and takes longer to run. On a Windows 10 computer with 64 GB RAM, this script takes around 4 hours to run. 

This is the `sessionInfo()` output in the local computer after running `replication-main-figs`:

```
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.utf8  LC_CTYPE=C                              LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C                            LC_TIME=English_United Kingdom.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] stargazer_5.2.3  ggpubr_0.5.0     purrr_0.3.4      stringr_1.4.1    ggplot2_3.4.0    tidyr_1.2.1      dplyr_1.0.9      texreg_1.38.6    ri2_0.4.0        estimatr_1.0.0   randomizr_0.22.0 margins_0.3.26  
[13] knitr_1.40      

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.2  xfun_0.33         listenv_0.9.0     carData_3.0-5     colorspace_2.0-3  vctrs_0.5.1       generics_0.1.2    htmltools_0.5.5   yaml_2.3.5        utf8_1.2.2        rlang_1.0.6      
[12] pillar_1.7.0      glue_1.6.2        withr_2.5.0       lifecycle_1.0.3   munsell_0.5.0     ggsignif_0.6.4    gtable_0.3.1      prediction_0.3.14 future_1.32.0     codetools_0.2-18  evaluate_0.16    
[23] labeling_0.4.2    fastmap_1.1.0     parallel_4.2.1    fansi_1.0.3       broom_1.0.2       Rcpp_1.0.9        backports_1.4.1   scales_1.2.1      abind_1.4-5       farver_2.1.1      parallelly_1.35.0
[34] digest_0.6.29     stringi_1.7.8     rstatix_0.7.1     cowplot_1.1.1     grid_4.2.1        cli_3.4.1         tools_4.2.1       magrittr_2.0.3    tibble_3.1.7      Formula_1.2-5     car_3.1-1        
[45] crayon_1.5.1      pkgconfig_2.0.3   MASS_7.3-57       ellipsis_0.3.2    data.table_1.14.6 rmarkdown_2.16    httr_1.4.4        rstudioapi_0.14   R6_2.5.1          globals_0.16.2    compiler_4.2.1   
```
